package com.fxf.srb.sms.service.Impl;

import com.fxf.common.exception.BusinessException;
import com.fxf.common.result.ResponseEnum;
import com.fxf.srb.sms.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.rmi.ServerException;
import java.util.Date;
import java.util.Map;

/**
 * @author 饭小范
 * @version 1.0
 * @description: TODO
 * @date 2021/5/29 11:56
 */
@Service
@Slf4j
public class SmsServiceImpl implements SmsService {

    @Resource
    private JavaMailSender javaMailSender;

    @Override
    public void sendMail(String addressee, Map<String, Object> param) {
        log.info("开始发送邮件");
        try {
            SimpleMailMessage message = new SimpleMailMessage();
            message.setSubject("test");
            message.setFrom("2099512771@qq.com");
            message.setTo(addressee);
            message.setText("验证码"+param.get("code"));
            javaMailSender.send(message);
            log.info("邮件发送成功");
        }catch (Exception e){
            log.error("邮件发送失败！！！");
            throw new BusinessException(ResponseEnum.ALIYUN_Mail_ERROR , e);
        }

    }
}
